------------------ fgui require start ------------------
local GuildSettingEnterSkin = require 'View/UIGuild/Skin/GuildSettingEnterSkin';
local GuildApplySkin = require 'View/UIGuild/Skin/GuildApplySkin';
local GuildNoticeSkin = require 'View/UIGuild/Skin/GuildNoticeSkin';
local GuildInfoSettingSkin = require 'View/UIGuild/Skin/GuildInfoSettingSkin';
------------------  fgui require end  ------------------
local UIGuildSettingSkin = Class("UIGuildSettingSkin");

function UIGuildSettingSkin:ctor(com)
    ------------------ fgui事件绑定start ------------------
    self:bindChild(com);
    self.ctl_state.onChanged:Add(self.onChange_Ctl_state,self);
    self:init();
    ------------------  fgui事件绑定end  ------------------
end

function UIGuildSettingSkin:bindChild(com)
    ------------------ fgui变量绑定start ------------------
    self.fguiObj = com;
    self.ctl_state = com:GetController("Ctl_state");
    self.com_enter = GuildSettingEnterSkin.New(com:GetChild("Com_enter"));
    self.com_apply = GuildApplySkin.New(com:GetChild("Com_apply"));
    self.com_notice = GuildNoticeSkin.New(com:GetChild("Com_notice"));
    self.com_modify = GuildInfoSettingSkin.New(com:GetChild("Com_modify"));
    ------------------  fgui变量绑定end  ------------------
end

function UIGuildSettingSkin:init()
    self.com_apply:setCloseCallback(self.switchToEnterPanel,self);
    self.com_notice:setCloseCallback(function()
            self:switchToEnterPanel();
        end
    );
    self.com_modify:setCloseCallback(function(needUpdateSetting)
        self:switchToEnterPanel(needUpdateSetting);
    end);
    self.com_enter:setClassifyCallback(function(classify) 
        self.ctl_state.selectedIndex = classify;
        if classify == 0 then
            self.com_enter:updateView();
        elseif classify == 1 then
            self.com_apply:updateView();
        elseif classify == 3 then
            self.com_modify:updateView();
        elseif classify == 4 then
            self.ctl_state.selectedIndex = 0;
            unionHandler.reqQuitUnion(logicMgr.GuildManager.getUnionId());
            unionHandler.reqUnionInfoMessage();--用来更新加入公会cd
        end
    end)
    self.com_enter.btn_membershipapplication:GetChild("UIRedDots"):GetController("c1").selectedIndex = logicMgr.GuildManager.hasApplyGuildMembers() and 2 or 0;
    UIRedDots.addViewListen(PanelResNames.UIGuildSetting, self.com_enter.fguiObj.name .. self.com_enter.btn_membershipapplication.name, self.com_enter.btn_membershipapplication, Config.RedDotsType.GuildApply);
end

function UIGuildSettingSkin:OnDestroy()
    ------------------ fgui事件移除start ------------------
    self:beforeDestroy();
    self.ctl_state.onChanged:Clear();
    self.com_enter:OnDestroy();
    self.com_apply:OnDestroy();
    self.com_notice:OnDestroy();
    self.com_modify:OnDestroy();
    ------------------  fgui事件移除end  ------------------
end

function UIGuildSettingSkin:onChange_Ctl_state(event) end

------------------  ↑ fgui事件句柄 ↑  ------------------

function UIGuildSettingSkin:setCloseCallback(func,target)
    self.com_enter:setCloseCallback(func,target);
end

function UIGuildSettingSkin:switchToEnterPanel()
    self.ctl_state.selectedIndex = 0;
    
end

function UIGuildSettingSkin:beforeDestroy()
    UIRedDots.removeViewEvent(PanelResNames.UIGuildSetting);
end

return UIGuildSettingSkin;
